<template>
  <div class="container">
    <div class="header">后台管理系统</div>
    <el-form
      ref="ruleFormRef"
      style="width: 300px"
      :model="ruleForm"
      :rules="rules"
      label-width="auto"
      class="demo-ruleForm"
      :size="formSize"
      status-icon
    >
      <el-form-item prop="username">
        <el-input v-model="ruleForm.username" placeholder="请填写你的用户名" />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="ruleForm.password"
          type="password"
          placeholder="请填写你的密码"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          @click="submitForm(ruleFormRef)"
          class="w-100"
        >
          登录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";

import { login } from "@/api/login";

const formSize = ref("default");
const ruleFormRef = ref();
const ruleForm = reactive({
  username: "admin",
  password: "admin",
});

const rules = reactive({
  username: [{ required: true, message: "请输入你的用户名", trigger: "blur" }],
  password: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
  ],
});

const submitForm = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      // 登录调用
      let res = await login(ruleForm);
      console.log(res);
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>
<style scoped>
.container {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  background-image: url("https://lianshangke.oss-cn-zhangjiakou.aliyuncs.com/static/img/bg.3f5dba7.png");
  background-position: 0 0;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.header {
  margin-bottom: 40px;
  text-align: center;
  font-size: 28px;
  color: #fff;
}
</style>